// 格式化日期为"YYYY-MM-DD"字符串格式
const formatDate = (date) => {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    return `${year}-${month}-${day} 00:00:00`;
  };
// 获取本日时间范围
  const getTodayRange = () => {
    const today = new Date();
    const start = new Date(today.getFullYear(), today.getMonth(), today.getDate());
    const end = new Date(start.getTime() + 24 * 60 * 60 * 1000);
    console.log([formatDate(start), formatDate(end)])
    return [formatDate(start), formatDate(end),1];
  };
  
  // 获取本周时间范围
  const getThisWeekRange = () => {
    const today = new Date();
    const year = today.getFullYear();
    const month = today.getMonth();
    const date = today.getDate();
    // 获取当前天往前数7天的日期
    const start = new Date(year, month, date - 7);
    // 当前天作为结束日期
    const end = new Date(year, month, date+1);
    console.log([formatDate(start), formatDate(end)])
    return [formatDate(start), formatDate(end),5];
  };
  
  // 获取本月时间范围
  const getThisMonthRange = () => {
    const today = new Date();
    const year = today.getFullYear();
    const month = today.getMonth();
    const date = today.getDate();
    // 创建当前日期减去一个月的日期对象
    const start = new Date(year, month - 1, date);
    const end = new Date(year, month, date+1);
    console.log([formatDate(start), formatDate(end)])
    return [formatDate(start), formatDate(end),3];
  };
  
  // 获取本年时间范围
  const getThisYearRange = () => {
    const today = new Date();
    const year = today.getFullYear();
    const month = today.getMonth();
    const date = today.getDate();
    // 计算去年的同一天
    const lastYearStart = new Date(year - 1, month, date);
    // 计算今年的同一天作为结束日期
    const thisYearEnd = new Date(year, month, date+1);
    console.log([formatDate(lastYearStart), formatDate(thisYearEnd)])
    return [formatDate(lastYearStart), formatDate(thisYearEnd),4];
  };

  export {
    getTodayRange,
    getThisWeekRange,
    getThisMonthRange,
    getThisYearRange,
    formatDate
  };
  
  